/*
 * Copyright (c) 2012 Xilinx, Inc.  All rights reserved.
 *
 * Xilinx, Inc.
 * XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
 * COURTESY TO YOU.  BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
 * ONE POSSIBLE   IMPLEMENTATION OF THIS FEATURE, APPLICATION OR
 * STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION
 * IS FREE FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE
 * FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
 * XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
 * THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO
 * ANY WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE
 * FROM CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 */

#include <stdio.h>
#include "axidma0/demo.h"
uint16_t rc=0;
char c[4] = {0};
unsigned char buf[1024] = {};
unsigned char recv_buf[1024] = {};
int fd_irq = -1, Oflags = -1;
void my_signal_fun(int signum);
int main()
{
	axidmaInit();
	signal(SIGIO, my_signal_fun);
	fd_irq = open("/dev/mymodule", O_RDWR);
	if(fd_irq < 0)
	{
		printf("open /dev/mymodule failed \n");
	}
	fcntl(fd_irq, F_SETOWN, getpid());
	Oflags = fcntl(fd_irq, F_GETFL);
	fcntl(fd_irq, F_SETFL, Oflags | FASYNC);

	for(int i = 0; i<1024; i++){
		buf[i] = 5 ;
	}

	while(1)
	{
		printf("-------------------------------------------------------\n");
		bzero(c, sizeof(c));
		fgets(c, sizeof(c), stdin);

		if(c[0] == 's')
		{
			gtx_send(buf, 200);
			buf[0]++ ;
			buf[1]++ ;
		}
		if(c[0] == 'r')
		{
			gtx_recv(recv_buf) ;
			for(int i=0; i<10; i++)
			{
				printf("%x ", recv_buf[i]);
			}
			printf("\n");
		}
	}
	return 0;
}


void my_signal_fun(int signum)
{
	gtx_recv(recv_buf) ;
	for(int i=0; i<10; i++)
	{
		printf("%x ", recv_buf[i]);
	}
	printf("\n");
}
